﻿using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Net;
using PicasaAPI;
using System.Collections.Generic;
using Google.GData.Photos;
using Google.GData.Extensions.MediaRss;

/// <summary>
/// Summary description for Picasa
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Picasa : System.Web.Services.WebService
{

    public Picasa()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld()
    {
        WebClient wc = new WebClient();
        string data=wc.DownloadString("http://picasaweb.google.com/data/feed/base/user/redmoon17?kind=album&access=public");
        return data;
    }

    [WebMethod]
    public List<Album> GetAlbums(string user)
    {
        PicasaService picasaService = new PicasaService("PicasaWS");
        AlbumQuery query = new AlbumQuery();
        query.Uri = new Uri(PicasaQuery.CreatePicasaUri(user));
        query.Access = PicasaQuery.AccessLevel.AccessPublic;

        PicasaFeed picasaFeed = picasaService.Query(query);

        List<Album> lst = new List<Album>();
        if (picasaFeed != null && picasaFeed.Entries.Count > 0)
        {
            foreach (PicasaEntry entry in picasaFeed.Entries)
            {
                Album obj = new Album();

                AlbumAccessor entryAccessor = new AlbumAccessor(entry);
                obj.Access = entryAccessor.Access;
                obj.AlbumAuthor = entryAccessor.AlbumAuthor;
                obj.AlbumAuthorNickname = entryAccessor.AlbumAuthorNickname;
                obj.AlbumSummary = entryAccessor.AlbumSummary;
                obj.AlbumTitle = entryAccessor.AlbumTitle;
                obj.BytesUsed = entryAccessor.BytesUsed;
                obj.CommentCount = entryAccessor.CommentCount;
                obj.CommentingEnabled = entryAccessor.CommentingEnabled;
                obj.Id = entryAccessor.Id;
                obj.Latitude = entryAccessor.Latitude;
                obj.Location = entryAccessor.Location;
                obj.Longitude = entryAccessor.Longitude;
                obj.Name = entryAccessor.Name;
                obj.NumPhotos = entryAccessor.NumPhotos;
                obj.NumPhotosRemaining = entryAccessor.NumPhotosRemaining;

                MediaThumbnail thumb = entry.Media.Thumbnails[0];
                obj.Thumbnail_Url = thumb.Attributes["url"] as string;

                lst.Add(obj);
            }
        }

        return lst;
    }
}

